<template>
	<view>
		<view class="text-base mx-4 mt-4">说明：【7列选号池过滤2】和【前区+后区选号池过滤3】是最优方案。</view>
		<uni-collapse>
			<uni-collapse-item
				:title="`前区+后区选号池过滤${i} (x${poolListCounter[`front${i}len`]} + x${poolListCounter[`back${i}len`]})`"
				v-for="i in 3" :key="i">
				<view class="mx-4 text-base lh-lg">
					{{ poolList[`front${i}`].join(', ') + ' + ' + poolList[`back${i}`].join(', ')}}
				</view>
			</uni-collapse-item>
			<uni-collapse-item :title="`7列选号池过滤${i}`" v-for="i in 3" :key="i">
				<view v-for="i2 in 7" :key="i2" class="mx-4 text-base lh-lg">
					<view>
						{{ '#'+i2 + ' (x'+poolListCounter[`col${i2 - 1}${i}len`]+')：' + poolList[`col${i2 - 1}${i}`].join(', ') }}
					</view>
				</view>
			</uni-collapse-item>
			<uni-collapse-item
				:title="`期号：${item.lotteryDrawNum}（${item.lotteryDrawTime} 星期${weekdays[new Date(item.lotteryDrawTime).getDay()]}）`"
				v-for="(item, idx) in dataset" :key="idx">
				<view class="mx-4 lh-lg text-base">
					<view>开奖结果：{{ item.lotteryDrawResult }}</view>
					<view v-for="i in 3" :key="i">
						{{ `【前区+后区选号池过滤${i}】：${item.stat[`FrontAndBack_LV${i}`][0]} + ${item.stat[`FrontAndBack_LV${i}`][1]}` }}
						（{{ item.stat[`FrontAndBack_LV${i}`][0] + item.stat[`FrontAndBack_LV${i}`][1] }}）
					</view>
					<view v-for="i in 3" :key="i">【7列选号池过滤{{ i }}】：
						{{ item.stat[`COL_LV${i}`][0].join(', ') + ' + ' + item.stat[`COL_LV${i}`][1].join(', ') }}
						（{{item.stat[`COL_LV${i}_COUNT`][0] + ' + ' +
					                    item.stat[`COL_LV${i}_COUNT`][1] + ' = ' + (item.stat[`COL_LV${i}_COUNT`][0]+item.stat[`COL_LV${i}_COUNT`][1])  }}）
						<view>
							<view v-for="i2 in 7" :key="i2" class="me-1 flex">
								<view>{{ '#' + i2 + '：'}}</view>
								<view
									v-html="renderColor(i2, poolList[`col${i2 - 1}${i}`], item.lotteryDrawResult).join(', ')">
								</view>
							</view>
						</view>
					</view>
				</view>
			</uni-collapse-item>
		</uni-collapse>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue';
	import SsqDataModel from '@/model/SsqDataModel';

	import ObjectUtils from "@/utils/ObjectUtils";
	import {
		split_index
	} from '@/config/ssq-config';

	let ssqDataModel = new SsqDataModel();
	const dataset = ref([...ssqDataModel.getDataSource()]);
	const statDrawal = ssqDataModel.getDrawalStat();

	const weekdays = ['日', '一', '二', '三', '四', '五', '六'];
	const poolList = ref({});
	const poolListCounter = ref({})
	for (let poolLevel = 1; poolLevel <= 3; poolLevel++) {
		poolList.value['front' + poolLevel] = ObjectUtils.statObjectToArr(statDrawal.statAll[0], false, {
			op: '>',
			value: poolLevel
		}).map(v => v.slice(-2));
		poolList.value['back' + poolLevel] = ObjectUtils.statObjectToArr(statDrawal.statAll[1], false, {
			op: '>',
			value: poolLevel
		}).map(v => v.slice(-2));
		for (let i = 0; i < 7; i++) {
			poolList.value['col' + i + poolLevel] = ObjectUtils.statObjectToArr(statDrawal.statColumns[i], false, {
				op: '>',
				value: poolLevel
			}).map(v => v.slice(-2));
		}
	}
	for (let poolLevel = 1; poolLevel <= 3; poolLevel++) {
		poolListCounter.value[`front${poolLevel}len`] = ('0' + poolList.value['front' + poolLevel].length).slice(-2);
		poolListCounter.value[`back${poolLevel}len`] = ('0' + poolList.value['back' + poolLevel].length).slice(-2);
		for (let i = 0; i < 7; i++) {
			poolListCounter.value[`col${i}${poolLevel}len`] = ('0' + poolList.value['col' + i + poolLevel].length).slice(-
				2);
		}
	}
	let arrTemp = [],
		orderArr = [],
		pos = 0,
		name = '';
	dataset.value.forEach(item => {
		arrTemp = item.lotteryDrawResult.split(' ');
		orderArr = [arrTemp.slice(0, split_index), arrTemp.slice(split_index)];
		item['stat'] = {};
		for (let poolLevel = 1; poolLevel <= 3; poolLevel++) {
			item['stat']['FrontAndBack_LV' + poolLevel] = [
				orderArr[0].filter(v => poolList.value['front' + poolLevel].includes(v)).length,
				orderArr[1].filter(v => poolList.value['back' + poolLevel].includes(v)).length
			];
			name = 'COL_LV' + poolLevel;
			item['stat'][name] = [
				[],
				[]
			];
			arrTemp.forEach((num, i) => {
				pos = i < split_index ? 0 : 1;
				item['stat'][name][pos].push(poolList.value['col' + i + poolLevel].includes(num) ? 'Y' :
					'N');
			})
		}
		for (let poolLevel = 1; poolLevel <= 3; poolLevel++) {
			item['stat']['COL_LV' + poolLevel + '_COUNT'] = [
				item['stat']['COL_LV' + poolLevel][0].filter(v => v == 'Y').length,
				item['stat']['COL_LV' + poolLevel][1].filter(v => v == 'Y').length
			];
		}
	})

	const renderColor = (idx, arr, drawResult) => {
		let arrTemp = [],
			resultArr = [],
			rowArr = [];
		arrTemp = drawResult.trim().split(' ');
		resultArr = [arrTemp.slice(0, split_index), arrTemp.slice(split_index)];
		arr.forEach(num => {
			if (resultArr[idx < split_index ? 0 : 1].includes(num)) {
				rowArr.push(`<strong class="text-red-400">${num}</strong>`);
			} else {
				rowArr.push(num);
			}
		})
		return rowArr;
	}
</script>